<%--
  Created by IntelliJ IDEA.
  User: xiaodo
  Date: 2021/11/1
  Time: 14:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页面</title>
    <%@include file="../headJs.jsp"%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/allcss/login.css">
    <script>
        if (window != top)
            top.location.replace(location.href);
    </script>
</head>
<body id="login" >
<%--
<form action="${pageContext.request.contextPath}/login">
    用户名:<input id="username" name="username" class="layui-input" placeholder="请输入用户名" required="required"/><br>
    密码：<input id="password" name="password" placeholder="密码" required="required"/>
    <button id="sub" onclick="ajaxLogin()">登录</button>
</form>

<script>
    function ajaxLogin(){
        var username = $('#username').val();
        var password = $('#password').val();

        $.ajax({
            url:"${pageContext.request.contextPath}/login/login",
            type:'post',
            dataType:'json',
            data:{username:username,password:password},
            success(data){
                if (data.blank == 'blank'){
                    alert("请输入用户名和密码")
                    // layer.msg('请输入用户名和密码！！！',{icon: 5});
                }else if (data.error == 'error'){
                    alert("你输入的用户名和密码错误")
                    // layer.msg('你输入的用户名和密码错误！！！',{icon: 2});
                }else {
                   window.location="${pageContext.request.contextPath}/login/main"
                    //window.location="http://www.baidu.com";

                }

            },
            error(data){

            }
        })
    }


</script>
--%>

<div class="login-wrapper">

    <div class="login-header">
        <img src="../static/images/logo_03.png">
    </div>

    <div class=" login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户登录
            </div>
            <form class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="username" type="text" lay-verify="required" placeholder="账号"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input name="password" type="password" lay-verify="required" placeholder="密码"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                    <div class="layui-input-block">
                        <div class="layui-row inline-block">
                            <div class="layui-col-xs7">
                                <input name="code" type="text" lay-verify="required" placeholder="验证码"
                                       class="layui-input">
                            </div>
                            <div class="layui-col-xs5" style="padding-left: 10px;">
                                <img class="login-captcha" src="${pageContext.request.contextPath}/login/captcha">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <a href="${pageContext.request.contextPath}/register/registerForm" class="layui-link">帐号注册</a>
                    <a href="${pageContext.request.contextPath}/login/checkForm" class="layui-link pull-right">忘记密码？</a>
                </div>
                <div class="layui-form-item">
                    <button lay-filter="login-submit" class="layui-btn layui-btn-fluid" lay-submit>登 录</button>
                </div>
                <div class="layui-form-item login-other">
                    <label>第三方登录</label>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>
                </div>
            </form>
        </div>
    </div>

    <div class="login-footer">
        <p> 2018 <a href="javascript:;" target="_blank">江西信息应用职业技术学院版权所有</a></p>
        <p>
            <span><a href="https://github.com/whvcse/EasyWeb" target="_blank">前往github</a></span>
            <span><a href="https://gitee.com/whvse/EasyWeb" target="_blank">前往gitee</a></span>
            <span><a href="javascript:;" target="_blank">文档说明</a></span>
        </p>
    </div>
</div>

<script>
    layui.use(['form','layer'],function (){
        var form =layui.form;
        var layer =layui.layer;
        form.on('submit(login-submit)',function (obj){
            layer.load(2);
            $.post(
                '${pageContext.request.contextPath}/login/login',
                obj.field,
                function (data){
                    if(data.success == 'success'){
                        layer.msg('登录成功',{icon:1,time:2000},function (){
                            // location.replace('./main');
                            window.location="${pageContext.request.contextPath}/login/main";
                        });
                    }else if (data.error == 'error'){
                        layer.closeAll('loading');
                        layer.msg('输入账号密码错误',{icon: 5})
                        $('.login-captcha').trigger('click');
                    }else if (data.yzm == 'yzm'){
                        layer.closeAll('loading');
                        layer.msg('验证码错误',{icon: 5})
                        $('.login-captcha').trigger('click');
                    }else {
                        layer.closeAll('loading');
                        layer.msg('请输入正确的账号密码',{icon: 5})
                        $('.login-captcha').trigger('click');
                    }
                },
                'JSON'
            );
            return false;
        })
    });


    //图形验证码
    $('.login-captcha').click(function () {
        this.src = this.src + '?t=' + (new Date).getTime();
    });
</script>

</body>
</html>
